<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
class CholeskyDecomposition
{
    private $L = [];
    private $m;
    private $isspd = true;
    public function __construct($A = NULL)
    {
        if($A instanceof Matrix) {
            $this->L = $A->getArray();
            $this->m = $A->getRowDimension();
            for ($i = 0; $i < $this->m; $i++) {
                for ($j = $i; $j < $this->m; $j++) {
                    $sum = $this->L[$i][$j];
                    $k = $i - 1;
                    while (0 <= $k) {
                        $sum -= $this->L[$i][$k] * $this->L[$j][$k];
                        --$k;
                    }
                    if($i == $j) {
                        if(0 <= $sum) {
                            $this->L[$i][$i] = sqrt($sum);
                        } else {
                            $this->isspd = false;
                        }
                    } elseif($this->L[$i][$i] != 0) {
                        $this->L[$j][$i] = $sum / $this->L[$i][$i];
                    }
                }
                for ($k = $i + 1; $k < $this->m; $k++) {
                    $this->L[$i][$k] = 0;
                }
            }
        } else {
            throw new PHPExcel_Calculation_Exception(JAMAError(ARGUMENT_TYPE_EXCEPTION));
        }
    }
    public function isSPD()
    {
        return $this->isspd;
    }
    public function getL()
    {
        return new Matrix($this->L);
    }
    public function solve($B = NULL)
    {
        if($B instanceof Matrix) {
            if($B->getRowDimension() == $this->m) {
                if($this->isspd) {
                    $X = $B->getArrayCopy();
                    $nx = $B->getColumnDimension();
                    for ($k = 0; $k < $this->m; $k++) {
                        for ($i = $k + 1; $i < $this->m; $i++) {
                            for ($j = 0; $j < $nx; $j++) {
                                $X[$i][$j] -= $X[$k][$j] * $this->L[$i][$k];
                            }
                        }
                        for ($j = 0; $j < $nx; $j++) {
                            $X[$k][$j] /= $this->L[$k][$k];
                        }
                    }
                    $k = $this->m - 1;
                    while (0 <= $k) {
                        for ($j = 0; $j < $nx; $j++) {
                            $X[$k][$j] /= $this->L[$k][$k];
                        }
                        for ($i = 0; $i < $k; $i++) {
                            for ($j = 0; $j < $nx; $j++) {
                                $X[$i][$j] -= $X[$k][$j] * $this->L[$k][$i];
                            }
                        }
                        --$k;
                    }
                    return new Matrix($X, $this->m, $nx);
                }
                throw new PHPExcel_Calculation_Exception(JAMAError(MatrixSPDException));
            }
            throw new PHPExcel_Calculation_Exception(JAMAError(MATRIX_DIMENSION_EXCEPTION));
        }
        throw new PHPExcel_Calculation_Exception(JAMAError(ARGUMENT_TYPE_EXCEPTION));
    }
}

?>